//
//  CarDetailViewController.m
//  HeWeiZhiNeng
//
//  Created by 林建 on 2017/12/16.
//  Copyright © 2017年 YanCeyMichael.github.io. All rights reserved.
//

#import "CarDetailViewController.h"
#import "CarDetailTableView.h"
#import "CellModel.h"

@interface CarDetailViewController ()<UITableViewDelegate>
@property (nonatomic, strong)CarDetailTableView *table;
@property (nonatomic, strong)NSMutableArray *dataArr;
@end

@implementation CarDetailViewController
- (NSMutableArray *)dataArr
{
    if (!_dataArr) {
        NSMutableArray *headArr = [NSMutableArray array];
        [headArr addObject:[self setUpModel:@"头像" content:nil type:@"image"]];
        
        NSMutableArray *userArr = [NSMutableArray array];
        [userArr addObject:[self setUpModel:@"IMEI号" content:[SingleManager shareManager].user.IMEI type:@"text"]];
        [userArr addObject:[self setUpModel:@"车型" content:[SingleManager shareManager].user.carType type:@"text"]];
        [userArr addObject:[self setUpModel:@"车架号" content:[SingleManager shareManager].user.VIN type:@"text"]];
        [userArr addObject:[self setUpModel:@"牌照" content:[SingleManager shareManager].user.licenseTag type:@"text"]];
        [userArr addObject:[self setUpModel:@"发电机号" content:[SingleManager shareManager].user.generator type:@"text"]];
        [userArr addObject:[self setUpModel:@"我的身份" content:[SingleManager shareManager].user.status type:@"text"]];
        
        NSMutableArray *footArr = [NSMutableArray array];
        [footArr addObject:[self setUpModel:@"解除绑定" content:nil type:@"button"]];
        
        _dataArr = [NSMutableArray arrayWithObjects:headArr, userArr, footArr, nil];
    }
    return _dataArr;
}

- (CellModel *)setUpModel:(NSString *)title content:(NSString *)content type:(NSString *)type
{
    CellModel *model = [[CellModel alloc]init];
    model.content = content;
    model.title   = title;
    model.type    = type;
    return model;
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
//    self.tabBarController.tabBar.hidden = YES;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor orangeColor];
    [self setUpNavigation];
    self.table.dataArr = self.dataArr;
//    nsl
    // Do any additional setup after loading the view.
}

- (void)setUpNavigation
{
    self.navigationController.navigationBar.translucent = NO;
    self.navigationController.navigationBar.barTintColor = Color.theme;
    UIButton *btn1 = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn1 addTarget:self action:@selector(leftBar1Clicked) forControlEvents:UIControlEventTouchUpInside];
    [btn1 setImage:[UIImage imageNamed:@"zhuce_fanhui"] forState:UIControlStateNormal];
    [btn1 sizeToFit];
    UIBarButtonItem *item1 = [[UIBarButtonItem alloc] initWithCustomView:btn1];
    self.navigationItem.leftBarButtonItem = item1;
    UILabel * titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 62, 20)];
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.text = @"车辆详情";
    titleLabel.textColor = Color.fullBtnTitle;
    titleLabel.font = Common_Font(18);
    self.navigationItem.titleView = titleLabel ;
}

- (void)leftBar1Clicked
{
    [self.rt_navigationController popViewControllerAnimated:YES];
    
}

- (CarDetailTableView *)table
    {
    if (!_table) {
        _table = [[CarDetailTableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
        _table.delegate = self;
        [self.view addSubview:_table];
        [_table mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.mas_equalTo(UIEdgeInsetsMake(0, 0, 0, 0));
        }];
    }
    return _table;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        return 120;
    } else {
        return 44;
    }
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *view=[[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenW, 10)];
    view.backgroundColor = UIColorFromRGB(0xeeeeee);
    return view;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 10;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 1;
}
//section底部视图
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    UIView *view=[[UIView alloc] initWithFrame:CGRectMake(0, 0,kScreenW, 1)];
    view.backgroundColor = [UIColor clearColor];
    return view;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
